package com.lyy.photovoltaic.config;

import com.alipay.easysdk.factory.Factory;
import com.alipay.easysdk.kernel.Config;
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;

@Component
@ConfigurationProperties(prefix = "alipay")
@Data
public class AliPayConfig {
    private String appId;
    private String alipayPublicKey;
    private String merchantPrivateKey;
    private String notifyUrl;
    private String protocol;
    private String gatewayHost;
    private String signType;

    @PostConstruct
    public void init() {
        Config config = new Config();
        config.protocol = this.protocol;
        config.gatewayHost = this.gatewayHost;
        config.signType = this.signType;
        config.appId = this.appId;
        config.merchantPrivateKey = this.merchantPrivateKey;
        config.alipayPublicKey = this.alipayPublicKey;
        config.notifyUrl = this.notifyUrl;
        Factory.setOptions(config);
        System.out.println("支付宝SDK初始化成功");
    }

    public Config getOptions() {
        Config config = new Config();

        config.appId = appId;
        //应用私钥
        config.merchantPrivateKey = merchantPrivateKey;
        //支付宝公钥
        config.alipayPublicKey = alipayPublicKey;
        //可设置异步通知接收服务地址（可选）
        config.notifyUrl = notifyUrl;
        return config;
    }
}